<?php
class User extends Zend_Db_Table{
	protected $_name='admin_user';

	public function __construct(){
			parent::__construct();			
			$this->db=Zend_Registry::get('dbAdapter');
	}

	function add($info)
	{
		Zend_Loader::loadClass('Zend_Filter_StripTags');
		$filter = new Zend_Filter_StripTags();
		$username = trim($filter->filter($info['username']));
		$realname = trim($filter->filter($info['realname']));
		$password = md5(trim($filter->filter($info['pwd1'])));
		$email  = trim($filter->filter($info['email']));
		$role = trim($filter->filter($info['role']));
		if($role==""){
			$role = trim($filter->filter($info['roleprivate']));
			}
		$input_date=date('Y-m-d H:i:s');
		if ($username && $realname) {
			$data = array(
				'username' => $username,
				'realname' => $realname,
				'password' => $password,
				'email'	   => $email,
				'role'     => $role,
				'input_date'=> $input_date
				);
			if (!empty($info['id'])) {
				if(empty($info['pwd1'])){
					$data = array(
				'username' => $username,
				'realname' => $realname,				
				'email'	   => $email,
				'role'     => $role,
				'input_date'=> $input_date
				);
				}
				else{
						print_r($password);
					}
				$id = intval($filter->filter($info['id']));
				$this->update($data,'u_id='.$id);	
			} else {
				$this->insert($data);
			}
			
			return true;
		}

	}
	

	
	function del($ids){		
		if(is_numeric($ids)){
			$this->delete("u_id=".$ids);
			return true;
			}
		else{
			$this->delete("u_id in ($ids)");
			return true;
			}
		}

}
?>